package com.softer.wxzj.controller;

import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.aop.annotation.LogRecord;
import com.softer.wxzj.common.aop.enums.LogOperationType;
import com.softer.wxzj.common.aop.enums.LogOperationUnit;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.entity.BaseBankInfo;
import com.softer.wxzj.mapper.BaseBankInfoMapper;
import com.softer.wxzj.service.BaseBankInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * BaseBankInfoController class
 *
 * @author zcz
 * @date 2019/4/10
 */
@RestController
@RequestMapping("/baseBankInfo")
@Slf4j
public class BaseBankInfoController {
@Autowired
    BaseBankInfoMapper baseBankInfoMapper;
    @Autowired
    BaseBankInfoService baseBankInfoService;

    /**
     * 用于下拉列表，查询所有银行
     */
    @RequestMapping("/getAllList")
    @LogRecord(description = "查询银行列表，不分页", operationUnit = LogOperationUnit.BASE_BANK_INFO, operationType = LogOperationType.SELECT)
    public List<BaseBankInfo> getAllList() {
        return baseBankInfoService.getAllList();
    }

    /**
     * 承办银行下拉列表
     *
     * @return 承办银行列表
     */
    @RequestMapping("/getListToAddBank")
    @LogRecord(description = "查询承办银行下拉列表", operationUnit = LogOperationUnit.BASE_CONTRACTOR_BANK_INFO, operationType = LogOperationType.SELECT)
    public List<BaseBankInfo> getListToAddBank() {
        return baseBankInfoService.getListToAddBank();
    }

    /**
     * 分页查询银行列表
     *
     * @param page         分页信息
     * @param baseBankInfo 查询实体
     * @param fuzzy        模糊查询字段
     * @return 银行列表
     */
    @RequestMapping("/getList")
    @LogRecord(description = "分页查询银行列表", operationUnit = LogOperationUnit.BASE_BANK_INFO, operationType = LogOperationType.SELECT)
    public PageInfo<BaseBankInfo> getList(Page page, BaseBankInfo baseBankInfo, String fuzzy) {
        return baseBankInfoService.getList(page, baseBankInfo, fuzzy);
    }


    /**
     * 新增银行
     *
     * @param baseBankInfo 银行信息
     * @return 新增结果
     */
//    @RequiresPermissions("bank_information:Newlyadded")
    @RequestMapping("/add")
    @LogRecord(description = "新增银行", operationUnit = LogOperationUnit.BASE_BANK_INFO, operationType = LogOperationType.INSERT)
    public CommonResult add(BaseBankInfo baseBankInfo) {
        return baseBankInfoService.insert(baseBankInfo);
    }

    /**
     * 查询银行详情
     *
     * @param id 银行ID
     * @return 银行详情
     */
    @RequestMapping("/detail")
    @LogRecord(description = "查询银行详情", operationUnit = LogOperationUnit.BASE_BANK_INFO, operationType = LogOperationType.SELECT)
    public BaseBankInfo detail(String id) {
        return baseBankInfoService.detail(id);
    }

    /**
     * 修改银行
     *
     * @param baseBankInfo 银行详情
     * @return 修改结果
     */
    @RequestMapping("/update")
    @LogRecord(description = "修改银行", operationUnit = LogOperationUnit.BASE_BANK_INFO, operationType = LogOperationType.UPDATE)
    public CommonResult update(BaseBankInfo baseBankInfo) {
        return baseBankInfoService.update(baseBankInfo);
    }

    @RequestMapping("/delete")
    @LogRecord(description = "删除银行", operationUnit = LogOperationUnit.BASE_BANK_INFO, operationType = LogOperationType.DELETE)
    public CommonResult delete(String id) {
        return baseBankInfoService.delete(id);
    }

    /**
     * 查询单个
     *
     * @param id
     * @return
     */
    @RequestMapping("/getInfo")
    @LogRecord(description = "查询单个", operationUnit = LogOperationUnit.BASE_BANK_INFO, operationType = LogOperationType.DELETE)
    BaseBankInfo baseBankInfo(String id) {
      return   baseBankInfoService.getInfo(id);
    }
}
